package com.fs.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fs.entity.Messages;
import com.fs.entity.ResponseData;
import com.fs.service.IMessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-06-12
 */
@RestController
@RequestMapping("/messages")
public class MessagesController {
    @Autowired
    IMessagesService messagesService;
    @GetMapping("SelectAllByid")
    public ResponseData SelectAllByid(Integer id) {
        List<Messages> messages=messagesService.SelectAllByid(id);
        return ResponseData.ok(messages);
    }
    @GetMapping("SelectMessagesbymid")
    public ResponseData SelectMessagesbymid(Integer mid)
    {
        Messages messages = messagesService.SelectMessagesbymid(mid);
        return ResponseData.ok(messages);
    }
    @PutMapping("Changeread")
    public ResponseData Changeread(Integer mid)
    {
       if(messagesService.Changeread(mid))
       {
           return ResponseData.ok();
       }
       return ResponseData.error("未知初五");
    }

    @PostMapping("AddMessage")
    public ResponseData AddMessage(Messages messages)
    {
        if(messagesService.AddMessage(messages))
        {
            return ResponseData.ok();
        }
        return ResponseData.error("未知初五");
    }
    @DeleteMapping("Deletebymids")
    public ResponseData Deletebymids(Integer[] mid)
    {
        if(messagesService.Deletebymids(mid))
        {
            return ResponseData.ok();
        }
        return ResponseData.error("未知初五");
    }
}
